package com.example.dddsample.application.api;

import com.example.commom.model.ApiResult;
import com.example.dddsample.application.api.response.CustomerResponseDTO;
import com.example.dddsample.application.service.CustomerAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping(value = "/api/v1/customer")
public class CustomerApi {

    private final CustomerAppService customerAppService;

    public CustomerApi(CustomerAppService customerAppService) {
        this.customerAppService = customerAppService;
    }


    @GetMapping("/{custId}")
    public ApiResult<CustomerResponseDTO> getCustomer(@PathVariable("custId") String custId) {
        return ApiResult.ok(customerAppService.getCustomer(custId));
    }

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @param custName
     * @return
     */
    @GetMapping("/customerPages")
    public ApiResult getPageCustomer(@RequestParam(name = "pageNum", defaultValue = "20") int pageNum,
                                     @RequestParam(name = "pageSize", defaultValue = "1") int pageSize,
                                     @RequestParam(name = "custName", defaultValue = "") String custName) {
        return ApiResult.ok(customerAppService.getPageCustomer(pageNum, pageSize, custName));
    }


    @GetMapping("/feignClientCustomer")
    public ApiResult getFeignClientCustomer(@RequestParam(name = "custId") String custId) {
        return customerAppService.getFeignClientCustomer(custId);
    }
}
